<table style="width: 95%" align="center" border="0">
<tr>
	<td valign="top" style="width: 510px" align="center"><div id="PanellistadeRecibos"></div></td>
	<td valign="top" style="width: 205px" align="center"><div id="Panellistadetalleoperacion"></div></td>
	<!-- <td valign="top">
		<div class="ui-widget ui-widget-content ui-corner-all" style="width: 272px; height: 220px;">
			<div align="center" class="ui-widget ui-state-default ui-corner-top ui-title">
		    	<label>Observaciones</label>
			</div>
			<div id="PanellistaObservaciones"></div>
		</div>
	</td>
	 -->
</tr>

<tr>
	<td valign="top" style="width: 510px" align="center"></td>
	<td valign="top" style="width: 205px" align="right">
		<button id="btnimpope">Imprimir</button>
	</td>
</tr>

</table>
<script type="text/javascript">

	isGridComplete = false;

	//idsigma,ctippag,vdescri,nmontot
	optiondetalleope = {
	        //height: 140,
	        height: 140,
	        width: 410,
	        //autowidth: true,
	        rownumbers: true,
	        rowNum: 1000,
	        colNames: [
	            'idsigma',
	            'tipo pago',
	            'Tipo de Pago',
	            'Nro. Operacion',
	            'Nro. Documento',
	            'Total',
	            'Total2'
	            
	        ],
	        colModel: [
	                   {name: 'idsigma', index:'idsigma', width: 328, align: 'left', hidden: true},
	                   {name: 'ctippag', index:'ctippag', width: 238, hidden: true},
	                   {name: 'vdescri', index:'vdescri', width: 100},
	                   {name: 'nnroope', index:'nnroope', width: 80, align:"right"},
	                   {name: 'dnrodoc', index:'dnrodoc', width: 80, align:"right"},
	                   {name: 'nmontot', index:'nmontot', width: 80, align:"right", sorttype:"float", formatter:"number", summaryType:'sum'},
	                   {name: 'nmontot2', index:'nmontot2', width: 80, align:"right", hidden: true}
	               ],
	               footerrow : true,
			caption: "&nbsp;&nbsp;&nbsp;Detalle de Pago"
	       	//onSelectRow: buscarDetalle
	    };

	// cnumcom,nmontotal,dfecpag1,dfecpag2,nestado,cidapertura,cnumope
	optionRecibos = {
        //height: 140,
        height: 140,
        width: 490,
        //autowidth: true,
        rownumbers: true,
        rowNum: 1000,
        colNames: [
            'Recibo',
            'Fecha Pago 1',
            'Fecha de Pago',
            'Total',
            'Estado',
            'IdApertura',
            'Numero Operacion',
            ' ',
        ],
        colModel: [
                   {name: 'cnumcom', index:'cnumcom', width: 328, align: 'left'},
                   {name: 'dfecpag1', index:'dfecpag1', width: 238, hidden: true},
                   {name: 'dfecpag2', index:'dfecpag2', width: 100, hidden: true},
                   {name: 'nmontotal', index:'nmontotal', width: 80, align:"right", sorttype:"float", formatter:"number", summaryType:'sum'},
                   {name: 'nestado', index:'nestado', width: 100, hidden: true},
                   {name: 'cidapertura', index:'cidapertura', width: 100, hidden: true},
                   {name: 'cnumope', index:'cnumope', width: 100, hidden: true},
                   {name: 'imp', index:'imp', width: 20},
               ],
               footerrow : true,
           		//userDataOnFooter : true,
           		//altRows : true,
               //grouping:true,
               //	toolbar: [true, "top"],
               /*groupingView : {
              		groupField : ['cnumope'],
              		groupSummary : [true],
              		groupColumnShow : [false],
              		groupText : ['<b>{0}</b>'],
              		groupCollapse : false,
           			groupOrder: ['asc']
              	},*/
		caption: "&nbsp;&nbsp;&nbsp;Recibos"
       	//onSelectRow: buscarDetalle
    };
	
	listarRecibos = function() {
		parameters = {
			"name": "tblListarRecibos",
			"print": "true",
			"procedure": "tesoreria.recibosxoperacion",
			"parameters": '{' +
			'"p_cnumope":"<?php echo $this->cnumope; ?>"' +
			'}'
		};	
		
		procesar = function(requestData){
			options = $.extend(optionRecibos, {
				data: requestData,
				datatype: "local",
				gridComplete: function(){
					isGridComplete = true;
					$("#tblListaRecibos").jqGrid('setSelection', 1, true);
					var grid = $("#tblListaRecibos"),
				    sum = grid.jqGrid('getCol', 'nmontotal', true, 'sum');

					grid.jqGrid('footerData','set', {ID: 'fnmontotal:', nmontotal: sum});
					grid.jqGrid('footerData','set', {ID: 'fcnumcom', cnumcom: 'Total',align:"right"});

					var ids = jQuery("#tblListaRecibos").jqGrid('getDataIDs');
					var impritodo ='';
					for(var i=0;i < ids.length;i++){
						var cl = ids[i];
						var rowdat = jQuery("#tblListaRecibos").jqGrid('getRowData',cl);
						buttimp='<div title="Imprimir Recibo Nro. '+rowdat.cnumcom+'" style="float: left; cursor: pointer; display: block;" class="ui-pg-div ui-inline-edit"  onmouseover="jQuery(this).addClass(\'ui-state-hover\');" onmouseout="jQuery(this).removeClass(\'ui-state-hover\')" onclick="imprimirreciboxoperacion(\''+rowdat.cnumcom+'\');"><span class="ui-icon ui-icon-print"></span></div>';
						impritodo +='imprimirreciboxoperacion(\''+rowdat.cnumcom+'\');';
						
						jQuery("#tblListaRecibos").jqGrid('setRowData',ids[i],{imp:buttimp});
					}
					console.log(impritodo);
					$('#btnimpope').click(function(){
							eval(impritodo);
					});
					
				}
			});
			procesarJSON("PanellistadeRecibos", "tblListaRecibos", optionRecibos, null, null);
		};
		procesarConsultaSubProceso("registrar", parameters, procesar, 'json');
	};
	
	listardetalleOpe = function() {
		parameters = {
			"name": "tblListardetope",
			"print": "true",
			"procedure": "tesoreria.imprimir_detallepago",
			"parameters": '{' +
			'"p_cnumope":"<?php echo $this->cnumope; ?>"' +
			'}'
		};	
		
		procesar = function(requestData){
			options = $.extend(optiondetalleope, {
				data: requestData,
				datatype: "local",
				gridComplete: function(){
					isGridComplete = true;
					$("#tblListardetope").jqGrid('setSelection', 1, true);

					var grid = $("#tblListardetope"),
				    sum = grid.jqGrid('getCol', 'nmontot2', true, 'sum');

					grid.jqGrid('footerData','set', {ID: 'fnmontot:', nmontot: sum});
					grid.jqGrid('footerData','set', {ID: 'fvdescri', vdescri: 'Total',align:"right"});

				}
			});
			procesarJSON("Panellistadetalleoperacion", "tblListardetope", optiondetalleope, null, null);
		};
		procesarConsultaSubProceso("registrar", parameters, procesar, 'json');
	};
	$(document).ready(function(){
		listarRecibos();
		listardetalleOpe();
		$('#btnimpope').button();
	});
</script>